<?php

include_once("../conf/global.config.php");

class Util {   
    public static function Logger($msg, $category = 'info', $depth = 1) {
        $debugInfo = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth);
        $file = $debugInfo[$depth - 1]['file'];
        $line = $debugInfo[$depth - 1]['line'];

        if (is_array($msg) || is_object($msg))
            $msg = print_r($msg, true);
        else if ($msg === null)
            $msg = 'NULL';
        else if ($msg === true)
            $msg = 'true';
        else if ($msg === false)
            $msg = 'false';
       
        $msg = "[" . date('Y-m-d H:i:s') . "] file $file line $line:\n$msg\n";
        
        $logfile = LOG_DIR . "$category.txt";
        @file_put_contents($logfile, $msg, FILE_APPEND);
    }
    public static function SendCurlGet($url,$get_data=array()){
    if(!empty($get_data)){
        $get_data_str=http_build_query($get_data);
        $url=preg_match("/\?/",$url) ? $url."&".$get_data_str : $url."?".$get_data_str;
    }
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  
    $output=curl_exec($ch);
    $http_state=curl_getinfo($ch);
    curl_close($ch);
    //return array($output,$http_state);
    return $output;
}
}